﻿<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>IP地址输入框</title>
    <style>
        div.IPDiv{background:#ffffff;width:120px;font-size:9pt;
            text-align:center;
            border-right:inset threedhighlight;border-bottom:inset threedhighlight;
        }
        input.IPInput{width:24px;font-size:9pt;text-align:center;border-width:0;
        }
    </style>

    <script language="javascript" for="document" event="onkeydown">
        if(event.keyCode==13)    //如果输入的是回车
            event.keyCode=9;         //转换为tab键
    </script>
    <script language="javascript">
        var tmpStr=[];           //创建一个数组
        for(var i=0;i<4;i++)     //通过循环-每隔3位，输出一个点
            tmpStr[i]="<input class=IPInput name=IPInput type=text size=3 maxlength=3 onkeydown='if(event.srcElement.value.length==3||event.keyCode==39)event.keyCode=9'>"+(i==3?"":".");
        document.write("<div class=IPDiv>"+tmpStr.join("")+"</div>");//输出字符串
    </script>
    
</head>
<body>

</body>
</html>